<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>

<script type="text/javascript">
	var matenproductgrid;
	$(function() {
		matenproductgrid = $('#matenproductgrid')
				.datagrid(
						{
							//title : '商品列表',
							url : '${ctx}/maintenance/product/list',
							striped : true,
							rownumbers : true,
							pagination : true,
							singleSelect : true,
							idField : 'id',	
							pageSize : 50,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
									400, 500 ],
							frozenColumns : [ [ {
								width : '120',
								title : '商品名称',
								field : 'productname'
								
							} ] ],
							columns : [ [
									{
										width : '150',
										title : '所属分类',
										field : 'pathname'
									},
									{
										width : '120',
										title : '所配车型',
										field : 'brandname'
									},
									{
										width : '80',
										title : '原价(元)',
										field : 'yprice'
									},
									{
										width : '80',
										title : '现价(元)',
										field : 'xprice'
									},
									{
										width : '120',
										title : '添加时间',
										field : 'createTime'
									},
									{
										width : '80',
										title : '状态',
										field : 'state',
										formatter : function(value, row, index) {
											switch (value) {
											case 0:
												return '未启用';
											case 1:
												return '启用';
											}
										}
									},
									{
										width : '150',
										title : '操作',
										field : 'action',
										formatter : function(value, row) {
											var str = "";
											str += sy
											.formatString(
													'<span onclick="matenproductremoveFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
													row.productid, "删除");
											
											
											str += sy
											.formatString(
													'<span onclick="matenproductupdateFun(\'{0}\');" style="margin-left:3px;cursor:pointer;">【{1}】</span>',
													row.productid, "修改");
											return str;
										}
									} ] ],
							toolbar : '#matenproducttoolbar',
							onBeforeLoad : function(param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(data) {
								$('.iconImg').attr('src', sy.pixel_0);
								$('#brandid').combotree({
									url : '${ctx}/maintenance/brand/treegrid',
									idFiled : 'id',
									textFiled : 'text',
									parentField : 'pid',
									lines : false,
									onLoadSuccess:function(){
										$('#brandid').combotree('tree').tree('collapseAll');
									}
								});
								$('#pathid').combotree(
										{
											url :'${ctx}/maintenance/path/treegrid',
											idfiled:'id',
											textFiled : 'text',
											parentField : 'pid',
											lines :true,
											onLoadSuccess:function(){
												
											}
										});
							
								parent.$.messager.progress('close');
							}
							
							
						});
	});

	

	//删除
	var matenproductremoveFun = function(id) {
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				$.post('${ctx}/maintenance/product/del/' + id, {
					id : id
				}, function() {
					matenproductgrid.datagrid('reload');
				}, 'json');
			}
		});
	};
	
	//添加
	var matenproductaddFun = function() {
		$('<div/>')
		.dialog(
				{
					href : '${ctx}/maintenance/product/Cru',
					width : 640,
					height : 190,
					modal : true,
					title : '添加商品',
					buttons : [ {
						text : '添加',
						iconCls : 'icon-add',
						handler : function() {
							var d = $(this).closest('.window-body');
							$('#Matnproduct_updateForms')
							.form('submit',
									{
										url : '${ctx}/maintenance/product/update/pro',
										success : function(result) {
											try {
												var r = $.parseJSON(result);
												if (r.success) {
													matenproductgrid.datagrid('reload'); // 刷新数据  
													d.dialog('destroy');
												
												}
												$.messager
												.show({
													title : '温馨提示',
													msg : r.message
												});
											

											} catch (e) {
												$.messager
												.show({
													title : '温馨提示',
													msg : r.message
												});
												return;
												
											}

										}

									});
				
						}

					} ],
					onLoad : function() {
						//$("#res_updateForm").form('load',entity);
						
					},
					onClose : function() {
						$(this).dialog('destroy');
					}
				});

};
	
	//修改
	var matenproductupdateFun = function(id) {
		$('<div/>')
				.dialog(
						{
							href : '${ctx}/maintenance/product/Cru?id=' + id,
							width : 640,
							height : 180,
							modal : true,
							title : '修改商品',
							buttons : [ {
								text : '修改',
								iconCls : 'icon-add',
								handler : function() {
									var d = $(this).closest('.window-body');
								
									$('#Matnproduct_updateForms').form(
													'submit',
													{
														url : '${ctx}/maintenance/product/update/pro',
														success : function(
																result) {
															try {
																var r = $.parseJSON(result);
															
																if (r.success) {
																	matenproductgrid.datagrid('reload'); // 刷新数据  
																	d.dialog('destroy');
																}
																
																$.messager
																.show({
																	title : '温馨提示',
																	msg : r.message
																});

															} catch (e) {
																$.messager
																		.alert(
																				'温馨提示',
																				r.message);
																return;
															}

														}

													});

								}

							} ],
							onLoad : function() {
								//$("#res_updateForm").form('load',entity);
							
							},
							onClose : function() {
								$(this).dialog('destroy');
							}
						});

	};
</script>
<!-- 界面布局  -->
<div class="easyui-layout" style="width: 100%; height: 100%;"
	data-options="fit:true,border:false">

	<div id="matenproducttoolbar" style="display: none;">

		<table>
			<tr>
				<td>
					<form id="matenproductsearchForm">
						<table>
							<tr style="font-size: 13px;">
								<td>商品</td>
								<td><input name="productname" style="width: 150px;" /></td>
								<td>车型</td>
								<td><input id="brandid" name="brandid"
									class="easyui-combotree" style="width: 155px;" /></td>
								<td>商品分类</td>
								<td><input id="pathid" name="pathid"
									class="easyui-combotree" style="width: 155px;" /></td>
								<td>创建时间</td>
								<td><input name="startime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 120px;" />-<input
									name="endtime" class="Wdate"
									onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
									readonly="readonly" style="width: 120px;" /></td>
								<td><a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search',plain:true"
									onclick="matenproductgrid.datagrid('load',sy.serializeObject($('#matenproductsearchForm')));">过滤</a><a
									href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-reload',plain:true"
									onclick="$('#matenproductsearchForm input').val('');productgrid.datagrid('load',{});">重置过滤</a></td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
			<tr>
				<td>
					<table>
						<tr>

							<td>
									<a href="javascript:void(0);" class="easyui-linkbutton"
										data-options="iconCls:'icon-add',plain:true"
										onclick="matenproductaddFun();">添加</a>
								</td>


						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',title:'保养产品管理'" style="padding: 2px;">
		<div class="easyui-layout" data-options="fit : true,border : false">
			<div data-options="region:'center',border:false">
				<table id="matenproductgrid" data-options="fit:true,border:false"></table>
			</div>
		</div>
	</div>
	<!-- 	<div data-options="region:'east', split:true" style="width: 320px;">
		<div class="easyui-panel"
			data-options="fit:true,border:false,title:'权限设置'"
			style="padding: 10px;" id="user-panel"></div>
	</div> -->
</div>